package de.blitzcoder.cddatabase.gui.datatable;

import javax.swing.RowFilter;
import javax.swing.RowFilter.Entry;

/**
 *
 * @author blitzcoder
 */
public class DataTableRowFilter extends RowFilter<DataTableModel, Integer> {

    private String filter = null;
    
    public void setFilter(String filter) {
        this.filter = filter;
    }

    @Override
    public boolean include(Entry<? extends DataTableModel, ? extends Integer> entry) {

        if (filter == null || filter.length() == 0)
            return true;

        DataTableModel model = entry.getModel();
        Integer i = entry.getIdentifier();
        DataTableRow row = model.getRow(i);
        return row.matches(filter);
    }

}
